﻿using Newtonsoft.Json;
using System.ComponentModel;
using System.Windows;
using VisionDesigner.ImageFilter;
using VM.Common.Enums;
using VM.Common.Helper;

namespace Plugin.Filter
{
    [JsonObject(MemberSerialization.OptOut)]
    public class ParamModel : NotifyPropertyBase
    {
        [Newtonsoft.Json.JsonIgnore]
        public Dictionary<string, string> ParamMap = new Dictionary<string, string>
        {

            { "高斯", "Gaussian" },
            { "均值", "Mean" },
            { "中值", "Median" },
            { "取反", "Invert" },



        };



        // 阈值方式
        private List<string> _FilterTypeArray = EnumHelper.GetEnumDescriptions<FilterTypes>();
        [Newtonsoft.Json.JsonIgnore]
        public List<string> FilterTypeArray
        {
            get { return _FilterTypeArray; }
            set { Set(ref _FilterTypeArray, value); }
        }
        //界面参数控件值大小的绑定
        private int _GaussKernelSize = 3;
        public int GaussKernelSize
        {
            get { return _GaussKernelSize; }
            set
            {
                Set(ref _GaussKernelSize, value);


            }

        }
        private int _KernelWidth = 3;
        public int KernelWidth
        {
            get { return _KernelWidth; }
            set
            {
                Set(ref _KernelWidth, value);

            }
        }

        private int _KernelHeight = 3;
        public int KernelHeight
        {
            get { return _KernelHeight; }
            set
            {
                Set(ref _KernelHeight, value);

            }
        }
        public string _FilterType = EnumHelper.GetEnumDescription(FilterTypes.Gaussian);
        [Newtonsoft.Json.JsonIgnore]
        public string FilterType
        {
            get { return _FilterType; }
            set
            {
                Set(ref _FilterType, value);
                UpdateThresholdVisible();
            }
        }

        //界面中参数控件的可视化
        private Visibility _GaussKernelVisible = Visibility.Visible;
        public Visibility GaussKernelVisible
        {
            get { return _GaussKernelVisible; }
            set { Set(ref _GaussKernelVisible, value); }
        }

        private Visibility _KernelWidthVisible = Visibility.Collapsed;
        public Visibility KernelWidthVisible
        {
            get { return _KernelWidthVisible; }
            set { Set(ref _KernelWidthVisible, value); }
        }


        private Visibility _KernelHeightVisible = Visibility.Collapsed;
        public Visibility KernelHeightVisible
        {
            get { return _KernelHeightVisible; }
            set { Set(ref _KernelHeightVisible, value); }
        }




        //二值化
        public void Filterupdata(CImageFilterTool cImagefilter)
        {//阈值方式
            cImagefilter.SetRunParam("FilterType", ParamMap[FilterType]);
            //值

            cImagefilter.SetRunParam("GaussKernelSize", GaussKernelSize.ToString());
            cImagefilter.SetRunParam("KernelWidth", KernelWidth.ToString());
            cImagefilter.SetRunParam("KernelHeight", KernelHeight.ToString());

        }



        private void UpdateThresholdVisible()
        {
            switch (FilterType)
            {
                case "高斯":
                    GaussKernelVisible = Visibility.Visible;
                    KernelHeightVisible = Visibility.Collapsed;
                    KernelWidthVisible = Visibility.Collapsed;

                    break;
                case "中值":
                    GaussKernelVisible = Visibility.Collapsed;
                    KernelHeightVisible = Visibility.Visible;
                    KernelWidthVisible = Visibility.Visible;

                    break;
                case "均值":
                    GaussKernelVisible = Visibility.Collapsed;
                    KernelHeightVisible = Visibility.Visible;
                    KernelWidthVisible = Visibility.Visible;

                    break;
                case "取反":
                    GaussKernelVisible = Visibility.Collapsed;
                    KernelHeightVisible = Visibility.Collapsed;
                    KernelWidthVisible = Visibility.Collapsed;

                    break;

                default:
                    break;
            }
        }


    }


    /// <summary>
    /// 输出图像
    /// </summary>

    public enum OutImageTypes
    {
        原图,
        滤波图像,

    }

    /// <summary>
    /// 阈值方式
    /// </summary>

    public enum FilterTypes
    {

        [Description("高斯")]
        Gaussian,

        [Description("中值")]
        Median,

        [Description("均值")]
        Mean,

        [Description("取反")]
        Invert,



    }


}
